import pandas
import requests
from lxml import etree
url="http://www.qdzpw.com/jobs/jobs_list/key/测试工程师.htm"
headers={
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35"
}
response=requests.get(url,headers=headers)
print(response.encoding)
print(response.status_code)
html=etree.HTML(response.text)
data_list=html.xpath("/html/body/div[5]/div[1]/div[2]/div")
comments=[]
for i in data_list:
    job_name=i.xpath("./div[2]/div[1]/a/@title")
    if len(job_name)!=0:
        job_name=job_name[0]
    job=i.xpath("./div[3]/a/text()")
    if len(job) != 0:
        job=job[0]
    money=i.xpath("./div[4]/text()")
    if len(money) != 0:
        money=money[0]
    date=i.xpath("./div[5]/text()")
    if len(date) != 0:
        date=date[0]
    zhiwei=i.xpath("./div[2]/div[1]/a/@href")
    if len(zhiwei)!=0:
        zhiwei=zhiwei[0]
        #print("http://www.qdzpw.com/"+zhiwei)
        zhiwei="http://www.qdzpw.com/"+zhiwei
    comments.append([job_name,job,money,date,zhiwei])
DataFram=pandas.DataFrame(comments)
DataFram.to_csv("3.csv")
# print(response.text)